package com.cssw.fyzb.busi.api.acct;

/**
 * @Author zhouxu
 * @create 2020-12-21 15:55
 */

import com.cssw.fyzb.busi.convert.Converter;
import com.cssw.fyzb.busi.service.acct.AcctService;
import com.cssw.fyzb.core.model.dodb.RnbExchangeGzDef;
import com.cssw.fyzb.core.model.vo.acct.RnbBuyGzCoinVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author yangyiqun
 * @create 2021-1-29 13:57
 */
@Function(description = "购买福币页面查询", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户ID", required = true),
}, result = @Result(
        listProperties = {
                @ListProperty(name = "list", properties = {
                        @Property(name = "gzCoin", type = Type.Decimal, description = "果子"),
                        @Property(name = "rnb", type = Type.Decimal, description = "人民币"),
                        @Property(name = "rgId", type = Type.Integer, description = "固定金额ID"),
                })
        }
))
@Component
public class BuyGzCoinView implements Action {

    private static final Logger logger = LoggerFactory.getLogger(BuyGzCoinView.class);

    @Autowired
    private AcctService acctService;

    @Override
    public Response execute(Request request) throws Exception {

        List<RnbExchangeGzDef> list = acctService.queryRnbBuyGzDef();
        List<RnbBuyGzCoinVo> voList = ((Converter<List<RnbExchangeGzDef>, List<RnbBuyGzCoinVo>>) tmpList -> {
            List<RnbBuyGzCoinVo> vos = new ArrayList<>();
            tmpList.forEach((v) -> {
                RnbBuyGzCoinVo vo = new RnbBuyGzCoinVo();
                vo.setGzCoin(v.getGzCoin());
                vo.setRnb(v.getRnb());
                vo.setRgId(v.getRgId());
                vos.add(vo);
            });
            return vos;
        }).convert(list);

        return Response.success().put("list", voList);
    }
}
